package robocup.component.actions;

import robocup.component.worldobjects.Player;

/**
 * This action performs an attentionto-command. This is an instant-action, which
 * causes the player to concentrate on the aural messages sent by the specified
 * player.
 */
public class AttentionToAction
    extends Action {

  /**
   * The player, on which the attention is set.
   */
  private Player communicator;

  /**
   * The teamname of the corresponding player.
   */
  private String teamName;

  /**
   * Constructor, sets the player to whom the attention should be set.
   * 
   * @param player -
   *          the player to whom the attention should be set
   * @param teamname -
   *          the name of the team of the given player
   */
  public AttentionToAction(
      final Player player,
      final String teamName) {

    super();
    this.communicator = player;
    this.teamName = teamName;
    this._type = Action.TYPE.ATTENTIONTO;
  }

  /**
   * Empty Constructor
   */
  public AttentionToAction() {

    super();
  }

  /**
   * This method translates the action into a String, which is a valid command
   * for the server of the format: (attentionto &lt;TeamName&gt; &lt;Number&gt;)
   */
  @Override
  public String toString() {

    if (this.communicator == null) {
      return "(attentionto off)";
    }
    final StringBuffer str = new StringBuffer();
    str.append("(attentionto ");
    str.append(this.teamName);
    str.append(" ");
    str.append(this.communicator.getNumber());
    str.append(")");
    return str.toString();
  }

  /**
   * returns the player to whom the attention should be set.
   * 
   * @return Player - the communicator.
   */
  public Player getCommunicator() {

    return this.communicator;
  }

  /**
   * @return Returns the teamName.
   */
  public String getTeamName() {

    return this.teamName;
  }

}